package com.ihr360.oneclick.controller;

import com.ihr360.commons.entity.AuthUserInfo;
import com.ihr360.commons.vo.ResultInfo;
import com.ihr360.oneclick.entity.StaffRecord;
import com.ihr360.oneclick.service.SpreadsheetRowService;
import com.ihr360.oneclick.service.StaffRecordService;
import com.ihr360.oneclick.service.WeChatApiService;
import com.ihr360.oneclick.vo.WechatFunctionVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author tom
 * @date 18-1-12
 */

@RestController
@RequestMapping
@Api(description = "微信相关接口", produces = ("application/json;charset=UTF-8"))
public class OneClickAppApiController {
    @Autowired
    private WeChatApiService weChatApiService;

    @Autowired
    private StaffRecordService staffRecordService;

    @Autowired
    private SpreadsheetRowService spreadsheetRowService;


    @GetMapping("/wechat/function/list")
    @ApiOperation(value = "/function/list", httpMethod = "GET", notes = "获取用户功能列表",
            consumes = "application/json;charset=UTF-8", produces = "application/json;charset=UTF-8")
    public ResultInfo<List<WechatFunctionVo>> getOneClickFunctions(AuthUserInfo authUserInfo) {
        List<WechatFunctionVo> data = weChatApiService.getOneClickFunctions(authUserInfo.getCompanyId());
        return new ResultInfo.Builder<List<WechatFunctionVo>>().success(data);
    }

    @PostMapping(value = "/staff/company")
    @ApiOperation(value = "/staff/company",httpMethod = "POST",notes = "根据手机号 获取最近6个月公司id与公司名称",consumes = "application/json;charset=UTF-8",produces = "application/json;charset=UTF-8")
    public List<String> getCompany(@RequestBody AuthUserInfo authUserInfo) {
        return spreadsheetRowService.findByMobileNo(authUserInfo.getMobileNo());
    }


    /************************ 下面接口由 aggregate 调用 ********************************/

    @PostMapping("/staff/info")
    @ApiOperation(value = "/staff/info", httpMethod = "POST", notes = "获取员工信息 微信端查看一键发布信息用于展示员工信息",
            consumes = "application/json;charset=UTF-8", produces = "application/json;charset=UTF-8")
    public StaffRecord getStaffRecord(@RequestBody AuthUserInfo authUserInfo) {
        return staffRecordService.getStaffRecordByCompanyIdAndMobileNo(authUserInfo.getCompanyId(),
                authUserInfo.getMobileNo());
    }
}
